package com.wg.net;

/**
 * 网络协议
 *
 * @author 少爷123
 */
public enum NetProtocol {
    /**
     * tcp协议
     */
    TCP("tcp"),
    /**
     * http协议
     */
    HTTP("http"),
    /**
     * https协议
     */
    HTTPS("https"),
    /**
     * ws协议
     */
    WEBSOCKET("ws"),
    /**
     * wss协议
     */
    WEBSOCKETS("wss");

    private final String prefix;

    NetProtocol(String prefix) {
        this.prefix = prefix;
    }

    public static NetProtocol valueOfByPrefix(String scheme) {
        if (TCP.prefix.equalsIgnoreCase(scheme)) {
            return TCP;
        }
        if (HTTP.prefix.equalsIgnoreCase(scheme)) {
            return HTTP;
        }
        if (HTTPS.prefix.equalsIgnoreCase(scheme)) {
            return HTTPS;
        }
        if (WEBSOCKET.prefix.equalsIgnoreCase(scheme)) {
            return WEBSOCKET;
        }
        if (WEBSOCKETS.prefix.equalsIgnoreCase(scheme)) {
            return WEBSOCKETS;
        }
        return null;
    }

    public String getPrefix() {
        return prefix;
    }
}
